<?php
/**
 *
 *
 * 功能说明：系统管理。
 *
 **/

namespace Qwadmin\Controller;

class TeamController extends ComController
{
    public function index()
    {
        $ulist = M('member')->where(['uid'=>$_SESSION['uid']])->find();
        // P($ulist);
        $list = M('member')->where(['ment'=>$ulist['ment']])->select();
        // dump($ulist);
        // exit;
        $slist = M('member')->where(['lead'=>$ulist['user']])->select();
        foreach ($slist as  $va) {
            $uid .= "`uid`="."'".$va['uid']."'"." or ";
        }
        $uid = rtrim($uid,'or ');
        // echo $uid;
        // exit;
        if (empty($uid)) {
            $empty = '1';
            $this->assign('empty',$empty);
            $this->display();
            exit;
        }
        $flist = M('type')->where($uid)->order('off asc')->select();
        // P($flist);
        $nian = date('Y');
    	$this->assign('nian',$nian);
        $this->assign('list',$list);
        $this->assign('flist',$flist);
    	$this->display();
    }




    //创建绩效辅导/面谈/周分享表格
    public function xuan()
    {	

    	$type = $_POST['type'];
    	$ulist = M('member')->where(['uid'=>$_SESSION['uid']])->find();
		$list['uname'] = $_POST['uname']; 
		$list['yue'] = substr($_POST['j_time'],5,2);
    	// P($type);
    	switch ($type) {
    		case '1': //绩效辅导表
    			
		    	// dump($list);
		    	// exit;
		    	$list['uname'] = $_POST['uname']; 
				$list['yue'] = substr($_POST['j_time'],5,2);
				$list['type'] = '绩效辅导表';
		    	$flist = M('type')->where($list)->select();

		    	if (!empty($flist)) {
		    	 	echo '请不要重复创建';
		    	 	exit;
		    	}else{

		    		$ullist = M('member')->where(['user'=>$list['uname'],'ment'=>$ulist['ment']])->select();
		    		// P($ullist);
		    		$arr['uid'] = $ullist[0]['uid'];
		    		$arr['uname'] = $ullist[0]['user'];
		    		$arr['pname'] = $ulist['user'];
		    		$arr['post'] = $ullist[0]['post'];
		    		$arr['ment'] = $ullist[0]['ment'];
		    		$arr['yue'] = substr($_POST['j_time'],5,2);
		    		$arr['type'] = '绩效辅导表';
		    		if (M('type')->add($arr) > 0) {
		    			echo '1111';
		    		}else{
		    			echo '2222';
		    		}

		    	}
    			break;
    		case '2':  //绩效面谈表

		    	$list['uname'] = $_POST['uname']; 
				$list['yue'] = substr($_POST['j_time'],5,2);
				$list['type'] = '绩效面谈表';
		    	$flist = M('type')->where($list)->select();
		    	// P($flist);
		    	if (!empty($flist)) {
		    	 	echo '请不要重复创建';
		    	 	exit;
		    	}else{

		    		$ullist = M('member')->where(['user'=>$list['uname'],'ment'=>$ulist['ment']])->select();
		    		// P($ullist);
		    		$arr['uid'] = $ullist[0]['uid'];
		    		$arr['uname'] = $ullist[0]['user'];
		    		$arr['pname'] = $ulist['user'];
		    		$arr['post'] = $ullist[0]['post'];
		    		$arr['ment'] = $ullist[0]['ment'];
		    		$arr['yue'] = substr($_POST['j_time'],5,2);
		    		$arr['type'] = '绩效面谈表';
		    		// P($arr);
		    		if (M('type')->add($arr) > 0) {
		    			echo '1111';
		    		}else{
		    			echo '2222';
		    		}

		    	}
    			break;

    		case '3': //绩效周分享
    			 $list['uname'] = $_POST['uname']; 
                                        $list['yue'] = substr($_POST['j_time'],5,2);
                                        $list['type'] = '绩效周分享表';
                                        $flist = M('type')->where($list)->select();
                                        // P($flist);
                                        if (!empty($flist)) {
                                            echo '请不要重复创建';
                                            exit;
                                        }else{

                                            $ullist = M('member')->where(['user'=>$list['uname'],'ment'=>$ulist['ment']])->select();
                                            // P($ullist);
                                            $arr['uid'] = $ullist[0]['uid'];
                                            $arr['uname'] = $ullist[0]['user'];
                                            $arr['pname'] = $ulist['user'];
                                            $arr['post'] = $ullist[0]['post'];
                                            $arr['ment'] = $ullist[0]['ment'];
                                            $arr['yue'] = substr($_POST['j_time'],5,2);
                                            $arr['type'] = '绩效周分享表';
                                            // P($arr);
                                            if (M('type')->add($arr) > 0) {
                                                echo '1111';
                                            }else{
                                                echo '2222';
                                            }

                                        }
    			break;
    	}
    	 


    }





    //绩效辅导表页面
    public function fu()
    {
    	switch ($_GET['type']) {
    		case '绩效辅导表':
    			// echo '1111';
    			// exit;
    				$flist = M('type')->where(['id'=>$_GET['id'],'type'=>$_GET['type']])->select();
			    	// P($flist);
			    	$nian = date('Y');
			    	$this->assign('list',$flist);
			    	$this->assign('nian',$nian);
			    	$this->display();
    			break;
    		case '绩效面谈表':
    				$flist = M('type')->where(['id'=>$_GET['id'],'type'=>$_GET['type']])->select();
			    	// P($flist);
			    	$nian = date('Y');
			    	$this->assign('list',$flist);
			    	$this->assign('nian',$nian);
			    	$this->display('mian');
    			break;
    		case '绩效周分享表':
    				$flist = M('type')->where(['id'=>$_GET['id'],'type'=>$_GET['type']])->select();
			    	// P($flist);
			    	$nian = date('Y');
			    	$this->assign('list',$flist);
			    	$this->assign('nian',$nian);
			    	$this->display('zhou');
    			break;
    		
    		
    	}
    }



    //绩效辅导/面谈/周分享表格填写
    public function add()
    {
    	// P(I());
     //        dump(I()); 
    	// exit;
            switch ($_POST['type']) {
                 case '绩效辅导表':
                        $data = $_POST['count'];
                        // P($data);
                        unset($_POST['count']);
                        foreach($data as $k => $v){
                            $arr[$k]['count'] = $v;
                            $arr[$k]['one'] = $_POST['one'][$k];
                            $arr[$k]['tow'] = $_POST['tow'][$k];
                            $arr[$k]['three'] = $_POST['three'][$k];
                            $arr[$k]['four'] = $_POST['four'][$k];
                            $arr[$k]['tid'] = $_POST['tid'];
                            $arr[$k]['uid'] = $_POST['uid'];
                            $arr[$k]['uname'] = $_POST['uname'];
                            $arr[$k]['pname'] = $_POST['pname'];
                            $arr[$k]['ment'] = $_POST['ment'];
                            $arr[$k]['post'] = $_POST['post'];
                            $arr[$k]['yue'] = $_POST['yue'];
                            $arr[$k]['off'] = '1';
                            $arr[$k]['type'] = $_POST['type'];

                        }
                        // dump($data);
                        // dump($_POST);
                        // dump($arr);exit();
                        if (M('fu')->addALL($arr) > 0) {
                            $off['off'] = '1';
                            if (M('type')->where(['id'=>$arr[0]['tid']])->save($off) > 0) {
                                $this->success('填写完成','index');
                            }
                            
                        }else{
                            $this->error('出现错误,请重新填写');
                        }
                     break;

                     case '绩效面谈表':
                            $list = $_POST;
                            $list['off'] = '1';
                            // dump($list);
                            if (M('mian')->add($list) > 0) {
                                $off['off'] = '1';
                                if (M('type')->where(['id'=>$list['tid']])->save($off) > 0) {
                                    $this->success('填写完成','index');
                                }
                            }else{
                                $this->error('出现错误，请重新填写！');
                            }
                     break;


                     case '绩效周分享表':
                           // dump(I());
                           $list = $_POST;
                            $list['off'] = '1';
                            // dump($list);
                            if (M('zhou')->add($list) > 0) {
                                $off['off'] = '1';
                                if (M('type')->where(['id'=>$list['tid']])->save($off) > 0) {
                                    $this->success('填写完成','index');
                                }
                            }else{
                                $this->error('出现错误，请重新填写！');
                            }
                     break;

             } 
    	
    }


}


